package com.tuojiahr.service.impl;

import java.util.Date;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.tuojiahr.common.HibernatePageCommon;
import com.tuojiahr.domain.TuoJiaHrOrdinaryColumn;
import com.tuojiahr.pagemodel.PageModel;
import com.tuojiahr.service.OrdinaryColumnService;
import com.tuojiahr.tools.StringUtil;

/**
 * 说明：
 *
 * @author wang.haibo
 * @date 2012-11-7 上午12:10:02
 */

@Transactional
public class OrdinaryColumnServiceImpl extends HibernatePageCommon implements
		OrdinaryColumnService {

	//添加
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void addOrdinaryColumn(TuoJiaHrOrdinaryColumn ordinaryColumn) {
		Date now = new Date();
		ordinaryColumn.setCreateTime(now);
		ordinaryColumn.setUpdateTime(now);
		getHibernateTemplate().persist(ordinaryColumn);
	}

	//更新
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void updateOrdinaryColumn(TuoJiaHrOrdinaryColumn ordinaryColumn) {
		ordinaryColumn.setUpdateTime(new Date());
		getHibernateTemplate().update(ordinaryColumn);
	}

	//删除
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void deleteOrdinaryColumn(String ids) {
		String[] idArr = ids.split("\\|");
		for (String id : idArr) {
			getHibernateTemplate().delete(getOrdinaryColumnById(Long.valueOf(id)));
		}
	}

	//根据id查询
	@Override
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public TuoJiaHrOrdinaryColumn getOrdinaryColumnById(long id) {
		return getHibernateTemplate().load(TuoJiaHrOrdinaryColumn.class, id);
	}
	
	// 根据名称模糊查询分页显示
	@Override
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public PageModel getOrdinaryColumn(String keyWord) {
		if(StringUtil.isNotBlank(keyWord)) {
			return this.searchPaginated("from TuoJiaHrOrdinaryColumn oc where oc.name like ? order by oc.orderNum", keyWord);
		}
		return this.searchPaginated("from TuoJiaHrOrdinaryColumn oc order by oc.orderNum");
	}

}
